package Frames;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComboBox;

public class mainF extends Frame implements Runnable {
    int[] foods ={0,0,0,0};
    JComboBox<String> kinds;
    TextField weight;
    public mainF() {
        super();
        Frame frame=new Frame("膳食营养管理系统");
        frame.setVisible(true);
        frame.setSize(750,600);
        frame.setBackground(Color.WHITE);
        frame.setLocation(900,500);
        frame.setResizable(false);
        frame.setLayout(null);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        Label kind = new Label("食物:");
        kind.setBounds(150,80,150,120);
        kind.setFont(new Font("",Font.BOLD,40));
        frame.add(kind);
        kinds=new JComboBox<>();
        kinds.addItem("牛肉");
        kinds.addItem("鸡肉");
        kinds.addItem("青菜");
        kinds.addItem("胡萝卜");
        kinds.setVisible(true);
        kinds.setFont(new Font("",Font.BOLD,40));
        kinds.setBounds(330,100,250,80);
        frame.add(kinds);
        Label kg = new Label("百克：");
        kg.setBounds(150,210,150,120);
        kg.setFont(new Font("",Font.BOLD,40));
        frame.add(kg);
        weight=new TextField();
        weight.setVisible(true);
        weight.setBounds(330,230,250,80);
        weight.setFont(new Font("",Font.BOLD,40));
        frame.add(weight);
        Button adding=new Button("添加");
        adding.setFont(new Font("",Font.BOLD,30));
        adding.setBounds(150,390,180,100);
        adding.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //将输入的食物添加至食物队列
                run();
            }
        });
        frame.add(adding);
        Button check=new Button("查询已摄入营养");
        check.setFont(new Font("",Font.BOLD,23));
        check.setBounds(470,390,180,100);
        check.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //读取所有已摄入的食物并输出摄入的营养
                try{
                    new PrintF(foods);
                }catch (Exception exp){
                    exp.printStackTrace();
                }

            }
        });
        frame.add(check);
    }
    @Override
    public void run() {
        try{
            foods[kinds.getSelectedIndex()]+=Integer.parseInt(weight.getText());
            new ToastF();
        }catch (Exception exp){
            new NToastF();
        }
    }
}
